package org.usp.poli.bipt.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;

public class Login {
	private final DialogBox loginDialogBox = new DialogBox();
	private final FlexTable layout = new FlexTable();
	private Button okLogin = new Button("OK");
    
    private Button cancelarLogin = new Button("Cancelar");
	public Login() {
		//--Diálogo de login
	    loginDialogBox.setGlassEnabled(true);
	    loginDialogBox.setAnimationEnabled(true);
	    VerticalPanel panelLogin = new VerticalPanel();
	    
	    // Create a table to layout the form options
	    
	    layout.setWidth("350px");
	    layout.setCellSpacing(6);
	    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();

	    // Add a title to the form
	    layout.setHTML(0, 0, "Login");
	    cellFormatter.setColSpan(0, 0, 2);
	    cellFormatter.setHorizontalAlignment(0, 0,
	        HasHorizontalAlignment.ALIGN_CENTER);

	    // Add some standard form options
	    layout.setHTML(1, 0, "Login");
	    layout.setWidget(1, 1, new TextBox());
	    layout.setHTML(2, 0, "Senha");
	    layout.setWidget(2, 1, new PasswordTextBox());
	    
	    final Grid advancedOptions = new Grid(1, 2);
	    advancedOptions.setCellSpacing(6);
	    advancedOptions.setHTML(0, 0, "E-mail");
	    advancedOptions.setWidget(0, 1, new TextBox());

	    // Add advanced options to form in a disclosure panel
	    DisclosurePanel advancedDisclosure = new DisclosurePanel(
	        "Clique aqui se esqueceu a senha");
	    advancedDisclosure.ensureDebugId("cwDisclosurePanel");
	    advancedDisclosure.setContent(advancedOptions);
	    layout.setWidget(3, 0, advancedDisclosure);
	    cellFormatter.setColSpan(3, 0, 2);
	    
	    //Botão para logar
	    
	    HorizontalPanel botoes = new HorizontalPanel();
	    botoes.setSpacing(10);
	    botoes.add(okLogin);
	    botoes.add(cancelarLogin);
	    layout.setWidget(4,0,botoes);
	    cellFormatter.setColSpan(4, 0, 2);
	    cellFormatter.setHorizontalAlignment(4, 0,
		        HasHorizontalAlignment.ALIGN_CENTER);
	    panelLogin.add(layout);
	    loginDialogBox.setText("Faça seu login");
	    loginDialogBox.add(panelLogin);
	    
	    
	}
	
	public Widget getBotaoOk(){
		return okLogin;
	}
	
	public Widget getBotaoCancelar(){
		return cancelarLogin;
	}
	
	public Widget getLogin(){
		return loginDialogBox;
	}
	
	public String getUserLogin(){
		return ((TextBox)layout.getWidget(1, 1)).getText();
	}
	
	public String getUserSenha(){
		return ((TextBox)layout.getWidget(2, 1)).getText();
	}

}
